import java.util.*;
// 定义链栈节点类
class StackNode {
    char data;
    StackNode next;
    public StackNode(char data) {
        this.data = data;
        this.next = null;
    }
}
// 定义链栈类
class LinkedStack {
    private StackNode top;
    public LinkedStack() {
        top = null;
    }
    // 入栈
    public void push(char item) {
        StackNode newNode = new StackNode(item);
        newNode.next = top;
        top = newNode;
    }
    // 出栈
    public char pop() {
        if (isEmpty()) {
            throw new RuntimeException("栈为空，无法出栈");
        }
        char c = top.data;
        top = top.next;
        return c;
    }
    // 判断栈是否为空
    public boolean isEmpty() {
        return top == null;
    }
}
public class day08 {
    // 判断字符串是否为回文的方法
    public static boolean isPalindrome(String str) {
        int length = str.length();
        LinkedStack stack = new LinkedStack();
        // 将字符串前半部分字符入栈
        for (int i = 0; i < length / 2; i++) {
            stack.push(str.charAt(i));
        }
        // 若字符串长度为奇数，跳过中间字符
        if (length % 2 != 0) {
            int midIndex = length / 2;
        }
        // 比较后半部分字符与栈中弹出字符
        for (int i = length / 2; i < length; i++) {
            if (stack.isEmpty() || str.charAt(i) != stack.pop()) {
                return false;
            }
        }
        return true;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入需要判断是否为密文的字符串：");
        String testStr = sc.nextLine();
        boolean result = isPalindrome(testStr);
        System.out.print("字符串：" + testStr);
        if(result){
            System.out.print(" 是回文");
        }else{
            System.out.print(" 不是回文");
        }
    }
}